home *** CD-ROM | disk | FTP | other *** search
- /* Julian Day program, by Brian E. Kessel (with assistance from Jim Perry).
- Formulas derived from Astronomical Formulae for Calculators, fourth
- edition, by Jean Meeus and Practical Astronomy with your Calculator,
- third edition, by Peter Duffit Smith. For more information on this
- program and others like it, you may call my BBS, M-42 (314) 997-5157 */
-
- #include <dos.h>
- #include <math.h>
- #include <conio.h>
-
- main(int argc, char *argv[])
- {
- struct date the_date;
- struct time the_time;
- int y, m, a, b, i;
- int flag = 0;
- long int temp, temp1;
- double DDdd, YYYYMMDDdd, YYYY, MM, day, hour, minute, second, jd;
- char *months[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
- "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
- char *s[10];
- void info();
-
- clrscr();
- lowvideo();
- gotoxy(10,10);
- if (argc<2) { /* if command line arg was not entered */
- getdate(&the_date); /* get the date from system clock */
- gettime(&the_time); /* get the time from system clock */
-
- YYYY=the_date.da_year; /* assign year to YYYY */
- MM=the_date.da_mon; /* assign month to MM */
- day=the_date.da_day; /* assign day to day */
-
- hour=the_time.ti_hour; /* hour */
- minute=the_time.ti_min; /* minute */
- second=the_time.ti_sec; /* second */
- flag = 1;
- cprintf("\n\rAt %.2d:%.2d:%.2d, on %d %s %d,", the_time.ti_hour,
- the_time.ti_min, the_time.ti_sec, the_date.da_day,
- months[the_date.da_mon - 1], the_date.da_year);
-
- }
- else {
- hour = atof(argv[1]);
- if (hour < 0 || hour > 23)
- info();
- minute = atof(argv[2]);
- if (minute < 0 || minute > 59)
- info();
- second = atof(argv[3]);
- if (second < 0 || second > 59)
- info();
-
- day = atof(argv[4]);
- if (day < 1 || day > 31)
- info();
- MM = atof(argv[5]);
- if (MM < 1 || MM > 12)
- info();
- if (MM == 2 && day > 29)
- info();
- YYYY = atof(argv[6]);
- cprintf("\n\rAt %.2d:%.2d:%.2d, on %s %s %s,", atoi(argv[1]),
- atoi(argv[2]), atoi(argv[3]), argv[4], months[MM - 1], argv[6]);
-
- }
-
- DDdd = second/60.0;
- DDdd += minute;
- DDdd = DDdd/60.0;
- DDdd += hour; /* convert time to decimal hours */
- DDdd = DDdd/24.0; /* convert to fraction of day */
- DDdd += day; /* add day, for decimal day number */
-
- YYYYMMDDdd = day*.0001;
- YYYYMMDDdd += MM*.01;
- YYYYMMDDdd += YYYY; /* create the number YYYY.MMDD */
-
- if (MM>2) { /* if month is greater than 2 */
- y = YYYY;
- m = MM;
- }
-
- if ((MM == 1) || (MM == 2)){ /* if month is 1 or 2 */
- y = YYYY - 1;
- m = MM + 12;
- }
-
- if (YYYYMMDDdd >= 1582.1015) { /* is the date in the Gregorian Calendar */
- a = y / 100;
- b = 2 - a + (a / 4);
- temp = 365.25 * y;
- temp1 = 30.6001 * (m + 1);
- jd = temp + temp1 + DDdd + 1720994.5 + b;
- }
- else {
- temp = 365.25 * y;
- temp1 = 30.6001 * (m + 1);
- jd = temp + temp1 + DDdd + 1720994.5;
- }
-
- highvideo();
- cprintf(" the Julian Day is %.5f.\n\r", jd);
- lowvideo();
- if (jd > 2400000.5)
- cprintf(" (The Modified Julian Day is %.5f.)\n\r",
- jd-2400000.5);
-
- if (flag)
- info();
-
- for (i = 0; i < 11; i++)
- cprintf("\n\r");
- normvideo();
- exit(0);
- }
-
- /*==========================================================================*/
- void info(void)
- {
- int i;
-
- lowvideo();
- cputs("\n\rFor a specific Julian Day, use the following format:");
- cputs("\n\r julday HH MM SS DD MM YYYY");
- for (i = 0; i < 7; i++)
- cprintf("\n\r");
- normvideo();
- exit(0);
- }
-